




/*
'===============================================================================
'  HNG.Portal.BL.TblPhotoManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblPhotoManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_TenAnh="TenAnh";
				
				public const String Field_Image="Image";
				
				public const String Field_Link="Link";
				
				public const String Field_TrangThai="TrangThai";
				
				public const String Field_DanhMucPhotoId="DanhMucPhotoId";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblPhotoManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_TenAnh,typeof(string));
			
						
			
			dt.Columns.Add(Field_Image,typeof(string));
			
						
			
			dt.Columns.Add(Field_Link,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
						
			
			dt.Columns.Add(Field_DanhMucPhotoId,typeof(int));
			
			            
            return dt;			
		}
			
		public TblPhotoEntity Convert_Entity(TblPhotoEntity _TblPhotoEntity,TblPhotoEntity _TblPhotoEntity_XML)
		{	
			
				
			_TblPhotoEntity.Id= _TblPhotoEntity_XML.Id;
				
			_TblPhotoEntity.TenAnh= _TblPhotoEntity_XML.TenAnh;
				
			_TblPhotoEntity.Image= _TblPhotoEntity_XML.Image;
				
			_TblPhotoEntity.Link= _TblPhotoEntity_XML.Link;
				
			_TblPhotoEntity.TrangThai= _TblPhotoEntity_XML.TrangThai;
				
			_TblPhotoEntity.DanhMucPhotoId= _TblPhotoEntity_XML.DanhMucPhotoId;
				
			
			return _TblPhotoEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblPhotoEntity Insert(TblPhotoEntity TblPhotoEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblPhotoEntity, true);
			}
			return TblPhotoEntity;
		}

		
		public TblPhotoEntity Insert(int Id, string TenAnh, string Image, string Link, bool TrangThai, int DanhMucPhotoId)
		{
			TblPhotoEntity _TblPhotoEntity = new TblPhotoEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblPhotoEntity.Id = Id;
				_TblPhotoEntity.TenAnh = TenAnh;
				_TblPhotoEntity.Image = Image;
				_TblPhotoEntity.Link = Link;
				_TblPhotoEntity.TrangThai = TrangThai;
				_TblPhotoEntity.DanhMucPhotoId = DanhMucPhotoId;
				adapter.SaveEntity(_TblPhotoEntity, true);
			}
			return _TblPhotoEntity;
		}

		public TblPhotoEntity Insert(string TenAnh, string Image, string Link, bool TrangThai, int DanhMucPhotoId)
		{
			TblPhotoEntity _TblPhotoEntity = new TblPhotoEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblPhotoEntity.TenAnh = TenAnh;
				_TblPhotoEntity.Image = Image;
				_TblPhotoEntity.Link = Link;
				_TblPhotoEntity.TrangThai = TrangThai;
				_TblPhotoEntity.DanhMucPhotoId = DanhMucPhotoId;
				adapter.SaveEntity(_TblPhotoEntity, true);
			}
			return _TblPhotoEntity;
		}

		public bool Update(TblPhotoEntity _TblPhotoEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblPhotoFields.Id == _TblPhotoEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblPhotoEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblPhotoEntity _TblPhotoEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblPhotoEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, string TenAnh, string Image, string Link, bool TrangThai, int DanhMucPhotoId)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblPhotoEntity _TblPhotoEntity = new TblPhotoEntity(Id);
				if (adapter.FetchEntity(_TblPhotoEntity))
				{
				
					_TblPhotoEntity.TenAnh = TenAnh;
					_TblPhotoEntity.Image = Image;
					_TblPhotoEntity.Link = Link;
					_TblPhotoEntity.TrangThai = TrangThai;
					_TblPhotoEntity.DanhMucPhotoId = DanhMucPhotoId;
					adapter.SaveEntity(_TblPhotoEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblPhotoEntity _TblPhotoEntity = new TblPhotoEntity(Id);
				if (adapter.FetchEntity(_TblPhotoEntity))
				{
					adapter.DeleteEntity(_TblPhotoEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblPhotoEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTenAnh(string TenAnh)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TenAnh == TenAnh);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByImage(string Image)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLink(string Link)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByDanhMucPhotoId(int DanhMucPhotoId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.DanhMucPhotoId == DanhMucPhotoId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblPhotoEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblPhotoEntity SelectOne(int Id)
		{
			TblPhotoEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblPhotoEntity _TblPhotoEntity = new TblPhotoEntity(Id);
				if (adapter.FetchEntity(_TblPhotoEntity))
				{
					toReturn = _TblPhotoEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblPhotoCollection = new EntityCollection( new TblPhotoEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, null, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTenAnh(string TenAnh)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TenAnh == TenAnh);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTenAnhRDT(string TenAnh)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TenAnh == TenAnh);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByImage(string Image)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByImageRDT(string Image)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Image == Image);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLink(string Link)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLinkRDT(string Link)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.Link == Link);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByDanhMucPhotoId(int DanhMucPhotoId)
		{
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.DanhMucPhotoId == DanhMucPhotoId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblPhotoCollection, filter, 0, null);
			}
			return _TblPhotoCollection;
		}
		
		// Return DataTable
		public DataTable SelectByDanhMucPhotoIdRDT(int DanhMucPhotoId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblPhotoCollection = new EntityCollection(new TblPhotoEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblPhotoFields.DanhMucPhotoId == DanhMucPhotoId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblPhotoCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
